﻿namespace RestaurantMenu.Library
{
    using System;

    public abstract class Product : IConsumable
    {
        protected NutritionFacts nutrition;
        protected decimal price;
        protected int weight;
        protected string name;

        protected Product()
        {         
        }
  
        protected Product(string name, decimal price, int weight)
        {
            this.Name = name;
            this.Price = price;
            this.Weight = weight;
        }

        public NutritionFacts Nutrition
        {
            get
            {
                return this.nutrition;
            }

            protected set
            {
                this.nutrition = value;
            }
        }

        public decimal Price
        {
            get
            {
                return this.price;
            }

            protected set
            {
                if ((value < 0) || (value > 1000))
                {
                    throw new InvalidRangeException<int>(string.Format("The price should be in range [{0}..{1}]!", 0, 1000), 0, 1000);

                }
                this.price = value;
            }
        }

        public int Weight
        {
            get
            {
                return this.weight;
            }

            protected set
            {
                if (value < 0)
                {
                    throw new ArgumentException("The weight should have possitive value!");
                }
                this.weight = value;
            }
        }

        public string Name
        {
            get
            {
                return this.name;
            }

            protected set
            {
                this.name = value;
            }
        }

        public int CalculateCalories()
        {
            return weight * nutrition.Calories / 100;
        }

        public string PrintNutritionInformation()
        {
            return this.Nutrition.ToString();
        }
    }
}
